﻿using Inovout.Descriptor;
using NHibernate.Mapping;
using System;
using System.Reflection;
using System.Linq;

namespace Inovout.Data.Domain
{
    public class DataObjectPropertyDescriptor : PropertyDescriptor
    {
        public Property NHibernatePersistentProperty { get; private set; }
        public DataObjectPropertyDescriptor(PropertyInfo propertyInfo, Property property)
            : base(propertyInfo)
        {
            NHibernatePersistentProperty = property;
        }
        public bool IsUnique
        {
            get {
                return NHibernatePersistentProperty.ColumnIterator.Any(c=>((Column)c).IsUnique);
            }
        }
        public Type MappingType
        {
            get { return NHibernatePersistentProperty.Type.ReturnedClass; }
        }

    }
}
